import React from "react";
import {LdhMapSelect, LdhInput, LdhRangePicker} from "@biz/Components";
import {LdhSearchForm, LdhSearchItem} from "@biz/PageCompnents";
import GUtils from "@/utils";


export default class Search extends React.Component {
    formRef = React.createRef();
    constructor(props) {
        super(props);
        this.onSearch = this.onSearch.bind(this);
    }

    componentDidMount() {
        let userPhone = GUtils.getQueryString("userPhone");
        if(userPhone){
            let {action, store} = this.props;
            let {so} = store;
            so.userPhoneLike = userPhone;
            action.search(so);
            this.formRef.current.setFieldsValue({userPhoneLike:userPhone});
        }else{
            let {action, store} = this.props;
            let {so} = store;
            action.search(so);
        }

    }


    onSearch(values) {
        let {action, store} = this.props;
        let {so} = store;
        so = {...so, ...values, pageNumber: 1};
        GUtils.dealDateRange(values.createTime,"createTime", so);

        action.search(so);
    }


    render() {
        let {store} = this.props;
        let {loading} = store;
        return <LdhSearchForm onSearch={this.onSearch} loading={loading} ref={this.formRef}>
            <LdhSearchItem label="手机号" name="userPhoneLike">
                <LdhInput />
            </LdhSearchItem>
            <LdhSearchItem label="时间" name="createTime">
                <LdhRangePicker />
            </LdhSearchItem>
        </LdhSearchForm>

    }
}